<?php
include "../../fun.php";
isLogin();
$db=conndb();
?>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>分类</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../static/layuiAdmin.std-v1.7.1/src/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../static/layuiAdmin.std-v1.7.1/src/layuiadmin/style/admin.css" media="all">
</head>

<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline" style="display:inline-block">
            <label class="layui-form-label">父类</label>
            <div class="layui-input-inline">
              <?php echo select_trees(1, $db, 0, "sortid"); ?>
            </div>
          </div>
          <div class="layui-inline" style="display:inline-block">
            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>

      <div class="layui-card-body">
        <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
        <script type="text/html" id="table-content-list">
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
              class="layui-icon layui-icon-edit"></i>编辑</a>
        </script>
      </div>
    </div>
  </div>

  <script src="../../static/layuiAdmin.std-v1.7.1/src/layuiadmin/layui/layui.js"></script>
  <script>
    layui.config({
      base: '../../static/layuiAdmin.std-v1.7.1/src/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['table', 'index'], function() {
      var table = layui.table,
        form = layui.form,
        $ = layui.$;

      //第一个实例
      table.render({
        elem: '#LAY-app-content-list',
        url: './list.php', //数据接口
        page: true, //开启分页
        limit: 5,
        limits: [5, 10, 15, 20],
        cols: [
          [ //表头
            {
              field: 'id',
              title: 'ID',
              width: 80,
              sort: true,
              fixed: 'left',
              align: 'center'
            }, {
              field: 'sortname',
              title: '类别名称',
              align: 'center'
            }, {
              field: 'parentname',
              title: '所属类别',
              align: 'center'
            }, {
              field: '',
              title: '操作',
              toolbar: '#table-content-list',
              align: 'center'
            } //toolbar值是模板元素的选择器  类似templet
          ]
        ]
      });

      //监听搜索
      form.on('submit(LAY-app-contlist-search)', function(data) {
        var field = data.field;

        // console.log(field);
        //执行重载
        table.reload('LAY-app-content-list', {
          where: field
        });
      });


      //行工具事件
      table.on('tool(LAY-app-content-list)', function(
      obj) { //注：tool 是工具条事件名，LAY-app-content-list 是 table 原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        // console.log(data.id);
        if (layEvent === 'edit') { //编辑
          //do something
          layer.open({
            type: 2,
            title: '修改类别',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['60%', '80%'],
            content: './edit.php?sortid=' + data.id
          });
        }
      });

    });
  </script>
</body>

</html>